<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
		<title>稻道工场 社区粮店</title>
		<link rel="stylesheet" href="__PUBLIC__css/reset.css" />
		<link rel="stylesheet" href="__PUBLIC__css/detail.css" />
	</head>
	<body>
		<div class="layout">
			<!--header-->
			<div class="wrapper">
				<div class="header">
					<a class="s_preson" href="{:U('Index/index')}" target="_blank"> < 首页</a>
					<div class="store">
						<span>{$GoodInfo.name}</span>
					</div>
				</div>
			</div>

		
		<div class="detail">
			<section class="show">
				<div class="main">
					<img src="__UPLOAD__pic_goods/{$GoodInfo.img}" alt="" title="" />
				</div>
			</section>
			<section class="price">
				<div class="d_title">{$GoodInfo.name}</div>
				<div class="d_price_del">售价 ￥<em>{$GoodInfo.shop_price}</em></div>
				<!--<div class="d_price">微信支付减：￥<em>{$GoodInfo.promote_price}元</em></div>-->
				<div class="d_action">
					<div class="d_add"><em class="prev" data="{$GoodInfo.id}">-</em><input type="text" size="5" value="{$isCartNum}"><em class="next" data="{$GoodInfo.id}" style="border:1px solid #FF0000;">+</em></div>
					<div class="d_buy">
                        <a href="{:U('Good/buy',array('id'=>$GoodInfo['id']))}">立即购买</a>
                        <!--<i class="d_box">加入购物车</i>-->
                    </div>
				</div>
			</section>
			<section class="container">
				<input type="radio" id="radio-det-1" name="radio-det" class="radio-det" checked /><label for="radio-det-1">发现更多不同</label>
				<input type="radio" id="radio-det-2" name="radio-det" class="radio-det" /><label for="radio-det-2">大安全，小报告</label>
				<div class="summary context">
					{$GoodInfo.desc}
				</div>

				<div class="report context">
					{$GoodInfo.safe_info}
				</div>
                <!--
				<div class="recommend">
					<div class="rec-title">诚意推荐</div>
					<p>70响有机坚持，只耕种真的好米。</p>
				</div>-->
			</section>
			<footer class="footer">
				<div class="footer-main">
					<div class="webInfo">
						<div class="slogan">原产精粹<span class="i-slogan">✔</span>健康好粮</div>
						<div class="tel">客服 400-865-5060</div>
					</div>
					<div class="goTop" id="goTop">
						<span class="login-btn"><i class="i-goTop">︿</i>返回顶部</span>
					</div>
				</div>
				<div class="copyright">©2015 北京食安城信息科技有限公司，并保留所有权利。</div>
			</footer>
		</div>
			
			<div class="addUp">
				<div class="s_shopping">
				<a href="{:U('Order/cart')}">
					<i class="s_icon s_up"></i>
					<em id="cartNum">{$cartNum}</em>
				</a>
				</div>
				<div class="total">总计:<p>￥<em id="cartPrice">{$cartPrice}</em></p></div>
				<div class="settlement">
				<a style="color:#FFFFFF" href="{:U('Order/cart')}">
				去结算
				</a>
				</div>
			</div>
		</div>
	</body>
</html>
<script type="text/javascript">
$(function(){
	(function(){
		var searchBtn  = $('.s_search_box');
		var searchTxt =  searchBtn.find('.s_searchBox');
		
		searchTxt.val('请输入商品名称');
		var val = searchTxt.val();
		
		searchTxt.focus(function(){
			var curVal = $(this).val();
			if(val==curVal){
				$(this).val('')
			}else if(curVal==''){
				$(this).val(val);
			}
			
		});
		searchTxt.blur(function(){
			var curVal = $(this).val();
			if(curVal==''){
				$(this).val(val);
			}
		});
		
		//商品加减统计
		var listItem = $('.price');
		var listAdd  = listItem.find('.d_action');
		for(var i=0;i<listItem.length;i++){
			fnMain(listItem.eq(i));
		};
				
		function fnMain(quantityCur){
			var oPrev = quantityCur.find('.prev');
			var oNext  =   quantityCur.find('.next');
			var formInput =   quantityCur.find('input');
			
			var num=0;
			
			function showHide(){
				if(num==0){
					oPrev.css({'display':'none'});
					formInput.css({'display':'none'});
				}else{
					oPrev.css({'display':'inline-block'});
					formInput.css({'display':'inline-block'});
				}
			}
			
			oPrev.click(function(){
				if(num>0){
					num--;
				};
				showHide();
				formInput.val(num);
                var productID=oPrev.attr("data");
                var number=num;
                $.ajax({
                    url:"{:U('Index/addCart')}",

                    type: 'POST',

                    data:{
                        productID:productID,
                        number:number
                    },

                    dataType: 'html',

                    timeout: 1000,

                    error: function(){alert('Error loading PHP document');},

                    success: function(result){
                        var one=result.split("/");
                        $("#cartNum").html(one[0]);
                        $("#cartPrice").html(one[1]);
                    }

                });
			});
			oNext.click(function(){
				num++;
				showHide();
				formInput.val(num);
                var productID=oNext.attr("data");
                var number=num;
                $.ajax({
                    url:"{:U('Index/addCart')}",

                    type: 'POST',

                    data:{
                        productID:productID,
                        number:number
                    },

                    dataType: 'html',

                    timeout: 1000,

                    error: function(){alert('Error loading PHP document');},

                    success: function(result){
                        var one=result.split("/");
                        $("#cartNum").html(one[0]);
                        $("#cartPrice").html(one[1])
                    }

                });
			});
		};
	})();
})

//返回顶部
	var goTop = document.getElementById('goTop');
	goTop.onclick = function(){
		gotoTop();
		return false;
	}
	function gotoTop(acceleration,stime) {
		   acceleration = acceleration || 0.1;
		   stime = stime || 10;
		   var x1 = 0;
		   var y1 = 0;
		   var x2 = 0;
		   var y2 = 0;
		   var x3 = 0;
		   var y3 = 0; 
		   if (document.documentElement) {
		       x1 = document.documentElement.scrollLeft || 0;
		       y1 = document.documentElement.scrollTop || 0;
		   }
		   if (document.body) {
		       x2 = document.body.scrollLeft || 0;
		       y2 = document.body.scrollTop || 0;
		   }
		   var x3 = window.scrollX || 0;
		   var y3 = window.scrollY || 0;
		 
		   var x = Math.max(x1, Math.max(x2, x3));
		   var y = Math.max(y1, Math.max(y2, y3));
		 
		   var speeding = 1 + acceleration;
		   window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
		 
		   if(x > 0 || y > 0) {
		       var run = "gotoTop(" + acceleration + ", " + stime + ")";
		       window.setTimeout(run, stime);
		   };
	  }
</script>